package com.xinchili.autoddl.autoClass.config;

import com.xinchili.autoddl.autoClass.processor.EntityProcessor;
import com.xinchili.autoddl.autoClass.properties.EntityScanProperties;
import com.xinchili.autoddl.autoClass.resolver.AbstractDdlLogic;
import com.xinchili.autoddl.autoClass.resolver.strategy.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(EntityScanProperties.class)
//这个注解的作用是：
//启用配置属性处理：
//告诉Spring Boot要处理带有 @ConfigurationProperties 注解的类
//将 EntityScanProperties 类注册为一个配置属性Bean
//自动注册Bean：
//自动将 EntityScanProperties 实例化并注册到Spring容器中
//无需在 EntityScanProperties 类上添加 @Component 或其他注册注解
//属性绑定：
//结合 EntityScanProperties 类上的 @ConfigurationProperties(prefix = "autoddl") 注解
//实现配置文件属性自动绑定到 EntityScanProperties 对象的字段
public class AutoDdlAutoConfiguration {

    // 注入继承的组建
    @Bean
    @ConditionalOnMissingBean(AbstractDdlLogic.class)
    public AbstractDdlLogic defaultDdlResolver() {
        return new DefaultDdlLogic();
    }

    @Bean
    public EntityProcessor entityProcessor(
            ColumnNameLogic nameResolver,
            ColumnTypeLogic typeResolver,
            TableCommentLogic tableResolver,
            ColumnCommentLogic columnResolver,
            EntityScanProperties properties,
            ScanLogic scanLogic
    ) {
        return new EntityProcessor(nameResolver, typeResolver, tableResolver, columnResolver, properties, scanLogic);
    }

    // 默认实现类，继承抽象基类但不做任何重写
    private static class DefaultDdlLogic extends AbstractDdlLogic {
        // 这里不需要任何实现，直接使用父类的默认方法
    }
}